package cn.edu.scau.cmi.xianjiehua.factory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class FactoryController implements Initializable {

	@FXML
	private ChoiceBox<String> choice;

	@FXML
	private Button show;
	
	@FXML
	private TextArea console;

	ObservableList<String> items = FXCollections.observableArrayList(InsuranceFactory.DIRVER_INJURED,
			InsuranceFactory.CAR_DAMAGE, InsuranceFactory.CASUALTIES,InsuranceFactory.MULTIPLE_ACCIDENTS);

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		choice.setItems(items);
	}

	public void ButtonAction(ActionEvent event) {
		String select = choice.getValue();
		InsuranceFactory factory;
		if(select.equals(InsuranceFactory.DIRVER_INJURED)) {
			factory = new DriverInjuredFactory();
		}else if(select.equals(InsuranceFactory.CAR_DAMAGE)){
			factory = new CarDamageFactory();
		}else if(select.equals(InsuranceFactory.CASUALTIES)){
			factory = new CasualtiesFactory();
		}else {
			factory = new MultipleAccidentsFactory();
		}
		console.appendText(factory.getInstance().toString()+"\n");
	}

}
